<template>
  <div class="component-teamInfo">
    <div class="component-mainHeader">
      <div class="top">
        <div class="topleft">
          <p>
            <span class="iconfont" style="color:#1abc9a;margin-right:3px;">&#xe607;</span>施工队信息
          </p>
        </div>
        <div class="topright">
          <el-button type="info" @click="$router.go(0)">
            <span style="font-weight:700;margin-right:5px;" class="iconfont">&#xe662;</span>刷新
          </el-button>
        </div>
      </div>
    </div>
    <div class="component-listHeader">
      <div class="search-header">
        <div class="left-title">
          <p class="left-text">
            <span class="iconfont">&#xe61e;</span>
            施工队信息
          </p>
          <div class="right">
            <button @click="$router.push({name:'exEditTeamInfo',params:{flag:0}})">添加施工队</button>
          </div>
        </div>
      </div>
    </div>

    <div class="table">
      <!--@selection-change="handleSelectionChange"-->
      <el-table
        ref="multipleTable"
        :data="teamInfo"
        tooltip-effect="dark"
        style="width: 1100px;margin:0 auto"
        border
      >
        <!--<el-table-column type="selection" align="center" width="55"></el-table-column>-->
        <el-table-column label="队员编号" align="center" prop="orgNumber"></el-table-column>
        <el-table-column label="施工队名称" align="center" prop="orgName"></el-table-column>
        <el-table-column label="联系方式" align="center" prop="userPhone"></el-table-column>
        <el-table-column label="账号" align="center" prop="userName"></el-table-column>
        <el-table-column label="是否启用" align="center" prop="userStatus">
          <template slot-scope="scope">
            <span v-if="scope.row.userStatus==1">启用</span>
            <span v-else>禁用</span>
          </template>
        </el-table-column>
        <el-table-column label="操作信息" align="center" width="160">
          <template slot-scope="scope">
            <a
              @click="handleSubmitManage(scope.$index, scope.row)"
              type="text"
              size="small"
              class="red"
            >编辑</a>
            <a @click="handleSignleDelete(scope.row)" type="text" size="small" class="red">删除</a>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 分页 -->
    <div class="component-paging" v-if="teamInfo.length > 0">
      <div class="table-bottom">
        <div class="bottom-left" style="margin-left: 42px;">
          <!--<button @click="handleDelete">删除</button>-->
        </div>
        <div class="paging">
          <div class="paging-left">
            <p>
              共
              <span>{{Math.ceil(total/pageSize)}}</span> 页/
              <span>{{total}}</span> 条数据
            </p>
          </div>
          <el-pagination
            background
            @size-change="SizeChange($event,dataInit,currentPage,pageSize)"
            @current-change="CurrentChange($event,dataInit,currentPage,pageSize)"
            :current-page="currentPage"
            :page-sizes="[10, 20, 30]"
            :page-size="pageSize"
            layout="sizes, prev, pager, next, jumper"
            :total="total"
          ></el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import area from '@/assets/js/area.js'
  import ElInput from "../../../node_modules/element-ui/packages/input/src/input";
  export default {
    components: {ElInput},
    name: "teamInfo",
    data() {
      return {
        ms_roleName:localStorage.getItem("roleName"),
        teamSearch: {
          team: "",
          type: "",
          area:area, //省市区
          workarea: ["", "", ""], //省市区
          pro:'',//项目部
        },
        teamInfo: [{
          name:'11'
        }],
        // 数据总条数
        total: 10,
        // 每页显示数据的条数
        pageSize: 10,
        // 当前显示的页面页码
        currentPage: 1,
        teamList:[],//施工队列表
        teamType:[],//施工队类型
        multipleSelection:[],//全选
        proList:[],//项目部列表
      };
    },
    mounted(){
      this.dataInit();
      /*this.dataInit();
       this.teamLists(); //施工队列表
       this.teamTypes();//施工队类型
       this.proLists();//项目列表*/
    },
    methods: {
      //项目部列表
      proLists(){
        let that = this;
        let suCb = function(res){
          that.proList = res.data.data;
          console.log(res.data)
        }
        let erCb = function(res){
          console.log(res)
        }
        let postData = {
        }
        let palyParam = {
          url: "/api/web/proTeam/getDeparName",
          methods:'post',
          data: postData,
          success: suCb,
          error: erCb,
        }
        that.$https(palyParam)
      },
      //施工队信息列表
      dataInit(){
        let that = this;
        let suCb = function(res){
          that.teamInfo = res.data.data.records;
          that.total = res.data.data.rowCount;
          console.log(res.data)
        }
        let erCb = function(res){
          console.log(res)
        }
        let postData = {
          pageCurrent: that.currentPage.toString(),
          pageSize:that.pageSize.toString(),
        }
        let palyParam = {
          url: "/api/web/ProConStructionManage/getProTeam",
          methods:'post',
          data: postData,
          success: suCb,
          error: erCb,
        }
        that.$https(palyParam)
      },
      //获取施工队列表
      teamLists(){
        let that = this;
        let suCb = function(res){
          that.teamList = res.data.data
          console.log(that.teamList)
        }
        let erCb = function(res){
          console.log(res)
        }
        let postData = {}
        let palyParam = {
          url: "/api/web/proTeam/getAllTeamList",
          methods:'post',
          data: postData,
          success: suCb,
          error: erCb,
        }
        that.$https(palyParam)
      },
      //获取施工队类型
      teamTypes(){
        let that = this;
        let suCb = function(res){
          that.teamType = res.data.data
//        console.log(that.teamType)
        }
        let erCb = function(res){
          console.log(res)
        }
        let postData = {}
        let palyParam = {
          url: "/api/web/proTeam/getTeamType",
          methods:'post',
          data: postData,
          success: suCb,
          error: erCb,
        }
        that.$https(palyParam)
      },
      //详情
      handleCheck(val){
        this.$router.push({name:"seeDetails",params: {
          id: val,
        }})
      },
      //省事级联
      getArea(value, selectedData) {
        const areaName = selectedData.map(item => item.label)
        this.args = [...areaName]
      },
      //全选
      handleSelectionChange(val) {
        let arr = [];
        if(val.length > 0){
          val.forEach( item => {
            arr.push(item.orgId)
            this.multipleSelection = arr;
          })
        }else{
          this.multipleSelection = [];
        }
        console.log(this.multipleSelection)
      },
      //编辑
      handleSubmitManage(val,vals){
        if(vals.userStatus=='1'){
          vals.isUse = true
        }else{
          vals.isUse = false
        }
        if(vals.workFunction.length>1){
          vals.checkList = vals.workFunction.split(",");
        }else{
          vals.checkList = vals.workFunction.split(" ");
        }
        this.$router.push({name:"exEditTeamInfo",params: {
          info:vals,
          flag:1
        }})
      },
      //删除
      del(val){
        let that = this;
        let suCb = function(res){
          that.$message({
            message: '删除成功',
            type: 'success'
          });
          that.dataInit()
        }
        let erCb = function(res){
          console.log(res)
        }
        let postData = {
          userId:val.userId,
          orgId:val.orgId
        }
        let palyParam = {
          url: "/api/web/ProConStructionManage/delProTeam",
          methods:'post',
          data: postData,
          success: suCb,
          error: erCb,
        }
        that.$https(palyParam)
      },
      //批量删除
      handleDelete() {
        let that = this;
        if(this.multipleSelection != undefined && this.multipleSelection.length >= 1){
          that.$confirm('确认删除吗？')
            .then(_ => {
              that.del(that.multipleSelection);
            })
            .catch(_ => {});
        }else{
          this.$alert('请选择所要删除的内容', '提示', {
            confirmButtonText: '明白了',
          });
        }
      },
      //单个删除
      handleSignleDelete(val){
        this.$confirm('确认删除吗？')
          .then(_ => {
            this.del(val);
          })
          .catch(_ => {});
      },
      //点击查询
      findRes(){
        this.currentPage = 1;
        this.dataInit();
      },
    }
  };
</script>

<style scoped>
  .component-searchHeader .search-header {
    width: 1100px;
    box-sizing: border-box;
    border: 1px solid rgba(228, 228, 228, 1);
    background-color: rgba(255, 255, 255, 1);
    margin: 20px auto 0;
  }

  .component-searchHeader .search-header .left-title {
    display: flex;
    justify-content: space-between;
    width: 100%;
    background-color: rgba(243, 243, 243, 1);
    height: 45px;
    box-sizing: border-box;
  }

  .component-searchHeader .search-header .left-title .left-text {
    width: 20%;
    color: #666;
    line-height: 45px;
    font-family: "微软雅黑";
    font-weight: 400;
    font-size: 12px;
    text-align: left;
    margin: 0 0 0 30px;
  }

  .component-searchHeader .right {
    width: 70%;
    display: flex;
    justify-content: flex-end;
    margin-right: 30px;
  }

  .component-searchHeader .right button {
    padding: 0 25px;
    height: 30px;
    margin: 8px 5px;
    line-height: 30px;
    font-size: 14px;
    color: #666;
    background-color: #fff;
    border: 1px solid #ccc;
  }

  .component-searchHeader .right button:hover {
    background-color: #f3f3f3;
    cursor: pointer;
  }
  .component-search-box {
    width: 1100px;
    box-sizing: border-box;
    background-color: #fff;
    border: 1px solid #e4e4e4;
    border-top: none;
    margin: 0 auto;
    text-align: left;
    padding-left: 30px;
    line-height: 60px;
    padding-bottom: 15px;
    padding-top: 15px;
  }
  .component-search-box .el-input__inner {
    height: 35px;
    display: inline-block;
  }
  .el-form-item {
    margin-bottom: 0;
  }
  .component-listHeader .search-header {
    width: 1100px;
    box-sizing: border-box;
    border: 1px solid rgba(228, 228, 228, 1);
    border-bottom: none;
    background-color: rgba(255, 255, 255, 1);
    margin: 20px auto 0;
  }

  .component-listHeader .search-header .left-title {
    display: flex;
    justify-content: space-between;
    width: 100%;
    background-color: rgba(243, 243, 243, 1);
    height: 45px;
    box-sizing: border-box;
  }

  .component-listHeader .search-header .left-title .left-text {
    width: 20%;
    color: #666;
    line-height: 45px;
    font-family: "微软雅黑";
    font-weight: 400;
    font-size: 12px;
    text-align: left;
    margin: 0 0 0 30px;
  }

  .component-listHeader .search-header .right {
    width: 70%;
    display: flex;
    justify-content: flex-end;
    margin-right: 10px;
  }

  .component-listHeader .search-header .right button {
    padding: 0 15px;
    height: 30px;
    width: 120px;
    margin: 6px 5px;
    line-height: 30px;
    font-size: 14px;
    color: #1abc9c;
    background-color: #fff;
    border: 1px solid #ccc;
  }
  .el-form-item {
    text-align: right;
    width: 310px;
  }
  .component-listHeader .search-header .right button:hover {
    background-color: #1abc9c;
    color: #fff;
  }
  .component-listHeader .search-header .right .right-select-margin {
    margin-top: 8px;
    margin-right: 8px;
  }
  /* 删除按钮 */
  .red {
    color: #48c9b0;
    font-size: 12px;
    cursor: pointer;
    margin-right: 4px;
  }
</style>
